package com.ozan.kemal.beans;

import java.util.ArrayList;
import java.util.List;

import javax.faces.event.ValueChangeEvent;
import javax.faces.model.SelectItem;

import com.ozan.kemal.text.LanguageMgr;

public class LanguageBean {
	
	private LanguageMgr langMgr = new LanguageMgr() ; 
	
	//strings in page
	public String language;	
	public String username;
	public String password;
	
	
	/**
	 *  available languages
	 */
	private List<SelectItem> languages = null;
	
	
	public String getLanguage() {
		return language;
	}
	public void setLanguage(String language) {
		this.language = language;
	}
	public LanguageMgr getLangMgr() {
		return langMgr;
	}
	public void setLangMgr(LanguageMgr langMgr) {
		this.langMgr = langMgr;
	}
	public String getUsername() {
		if (username== null || username.equals(""))
			username = langMgr.getString("USER_NAME");
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		if (password== null || password.equals(""))
			password = langMgr.getString("PASSWORD");
		
		return password;
	}
	
	public void setPassword(String password) {
		this.password = password;
	}
	
	
	public void setLanguages(List<SelectItem> languages) {
		this.languages = languages;
	}

	
	public void changeLanguage(ValueChangeEvent event){

		langMgr.setLanguage(event.getNewValue().toString());
		refreshStrings();
		
	}
	
	
	public void refreshStrings(){
		username=null;
		password=null;
		getPassword();
		getUsername();
		
	}

	public List<SelectItem> getLanguages() {

		if(languages==null){
			languages = new ArrayList<SelectItem>();
			languages.add(new SelectItem("TR", "Turkce"));
			languages.add(new SelectItem("EN", "English"));			
		}

		return languages;
	}

	
}
